class MassacreGameSurvival extends MassacreGame;

event InitGame( string Options, out string Error )
{
	Super.InitGame(Options, Error);
	InitialWave = 0;
	FinalWave = 8;
	TimeBetweenWaves = 90;
	//StartingCash = 1500;
	WaveStartSpawnPeriod=0.5;
}

function SetupWave()
{
	local int i,j;
	local float NewMaxMonsters;
	//local int m;
	local float DifficultyMod, NumPlayersMod;
	local int UsedNumPlayers;

	if ( WaveNum > 15 )
	{
		SetupRandomWave();
		return;
	}

	TraderProblemLevel = 0;
	rewardFlag=false;
	ZombiesKilled=0;
	WaveMonsters = 0;
	WaveNumClasses = 0;
	NewMaxMonsters = Waves[WaveNum].WaveMaxMonsters;

    // scale number of zombies by difficulty
	
//------Added---------------------------------------------------------
	if ( GameDifficulty >= 7.0 ) // Dies Irae
    {
    	DifficultyMod=2.25;
    }
//--------------------------------------------------------------------
    else if ( GameDifficulty >= 5.0 ) // Hell on Earth
    {
    	DifficultyMod=2.0;
    }
    else if ( GameDifficulty >= 4.0 ) // Suicidal
    {
    	DifficultyMod=1.7;
    }
    else if ( GameDifficulty >= 2.0 ) // Hard
    {
    	DifficultyMod=1.5;
    }
    else if ( GameDifficulty == 1.0 ) // Normal
    {
    	DifficultyMod=1.25;
    }

    UsedNumPlayers = NumPlayers + NumBots;

    // Scale the number of zombies by the number of players. Don't want to
    // do this exactly linear, or it just gets to be too many zombies and too
    // long of waves at higher levels - Ramm
	if( UsedNumPlayers < 2 )
		NumPlayersMod = 1.0;
	else if ( UsedNumPlayers < 7 )
		NumPlayersMod = 0.4 + 0.6 * UsedNumPlayers;
	else if ( UsedNumPlayers < 13 )
		NumPlayersMod = 2.0 + 0.3333333333333333 * UsedNumPlayers;	
	else
		NumPlayersMod = 6.0 + 0.0833333333333333 * UsedNumPlayers;

    NewMaxMonsters = NewMaxMonsters * DifficultyMod * NumPlayersMod;

    TotalMaxMonsters = Clamp(NewMaxMonsters,1,3000);

	MaxMonsters = Clamp(TotalMaxMonsters,1,MaxZombiesOnce+Max(0,UsedNumPlayers-8));
	//log("****** "$MaxMonsters$" Max at once!");

	KFGameReplicationInfo(Level.Game.GameReplicationInfo).MaxMonsters=TotalMaxMonsters;
	KFGameReplicationInfo(Level.Game.GameReplicationInfo).MaxMonstersOn=true;
	WaveEndTime = Level.TimeSeconds + Waves[WaveNum].WaveDuration;
	AdjustedDifficulty = GameDifficulty + Waves[WaveNum].WaveDifficulty;

	j = ZedSpawnList.Length;
	for( i=0; i<j; i++ )
		ZedSpawnList[i].Reset();
	j = 1;
	SquadsToUse.Length = 0;

	for ( i=0; i<InitSquads.Length; i++ )
	{
		if ( (j & Waves[WaveNum].WaveMask) != 0 )
		{
            SquadsToUse.Insert(0,1);
            SquadsToUse[0] = i;

            // Ramm ZombieSpawn debugging
            /*for ( m=0; m<InitSquads[i].MSquad.Length; m++ )
            {
               log("Wave "$WaveNum$" Squad "$SquadsToUse.Length$" Monster "$m$" "$InitSquads[i].MSquad[m]);
            }
            log("****** "$TotalMaxMonsters);*/
		}
		j *= 2;
	}

    // Save this for use elsewhere
    InitialSquadsToUseSize = SquadsToUse.Length;
    bUsedSpecialSquad=false;
    SpecialListCounter=1;

	//Now build the first squad to use
	BuildNextSquad();
}

function int ReduceDamage(int Damage, pawn injured, pawn instigatedBy, vector HitLocation, out vector Momentum, class<DamageType> DamageType)
{
	local float InstigatorSkill;
	local KFPlayerController PC;
	local float DamageBeforeSkillAdjust;

    if ( KFPawn(Injured) != none )
	{
		if ( KFPlayerReplicationInfo(Injured.PlayerReplicationInfo) != none && KFPlayerReplicationInfo(Injured.PlayerReplicationInfo).ClientVeteranSkill != none )
		{
			Damage = KFPlayerReplicationInfo(Injured.PlayerReplicationInfo).ClientVeteranSkill.Static.ReduceDamage(KFPlayerReplicationInfo(Injured.PlayerReplicationInfo), KFPawn(Injured), KFMonster(instigatedBy), Damage, DamageType);
		}
	}

	// This stuff cuts thru all the B.S
	if ( DamageType == class'DamTypeVomit' || DamageType == class'DamTypeWelder' || DamageType == class'SirenScreamDamage' )
	{
		return damage;
	}

	if ( instigatedBy == None )
	{
		return Super(xTeamGame).ReduceDamage( Damage,injured,instigatedBy,HitLocation,Momentum,DamageType );
	}

	if ( Monster(Injured) != None )
	{
		if ( instigatedBy != None )
		{
			PC = KFPlayerController(instigatedBy.Controller);
			if ( Class<KFWeaponDamageType>(damageType) != none && PC != none )
			{
				Class<KFWeaponDamageType>(damageType).Static.AwardDamage(KFSteamStatsAndAchievements(PC.SteamStatsAndAchievements), Clamp(Damage*(1.0/(1.0+0.75*float(Max(0,(WaveNum-1))))*(1.0+0.1*float(Max(0,WaveNum-1)))), 1, Injured.Health));
			}
		}

		return Damage;
	}

	if ( MonsterController(InstigatedBy.Controller) != None )
	{
		InstigatorSkill = MonsterController(instigatedBy.Controller).Skill;
		if ( NumPlayers > 4 )
			InstigatorSkill += 1.0;
		if ( (InstigatorSkill < 7) && (Monster(Injured) == None) )
		{
			if ( InstigatorSkill <= 3 )
				Damage = Damage;
			else Damage = Damage;
		}
	}
	else if ( KFFriendlyAI(InstigatedBy.Controller) != None && KFHumanPawn(Injured) != none  )
		Damage *= 0.25;
	else if ( injured == instigatedBy )
		Damage = Damage * 0.5;


	if ( InvasionBot(injured.Controller) != None )
	{
		if ( !InvasionBot(injured.controller).bDamagedMessage && (injured.Health - Damage < 50) )
		{
			InvasionBot(injured.controller).bDamagedMessage = true;
			if ( FRand() < 0.5 )
				injured.Controller.SendMessage(None, 'OTHER', 4, 12, 'TEAM');
			else injured.Controller.SendMessage(None, 'OTHER', 13, 12, 'TEAM');
		}
		if ( GameDifficulty <= 3 )
		{
			if ( injured.IsPlayerPawn() && (injured == instigatedby) && (Level.NetMode == NM_Standalone) )
				Damage *= 0.5;

			//skill level modification
			if ( MonsterController(InstigatedBy.Controller) != None )
				Damage = Damage;
		}
	}

	if( injured.InGodMode() )
		return 0;
	if( instigatedBy!=injured && MonsterController(InstigatedBy.Controller)==None && (instigatedBy.Controller==None || instigatedBy.GetTeamNum()==injured.GetTeamNum()) )
	{
		if ( class<WeaponDamageType>(DamageType) != None || class<VehicleDamageType>(DamageType) != None )
			Momentum *= TeammateBoost;
		if ( Bot(injured.Controller) != None )
			Bot(Injured.Controller).YellAt(instigatedBy);

		if ( FriendlyFireScale==0.0 || (Vehicle(injured) != None && Vehicle(injured).bNoFriendlyFire) )
		{
			if ( GameRulesModifiers != None )
				return GameRulesModifiers.NetDamage( Damage, 0,injured,instigatedBy,HitLocation,Momentum,DamageType );
			else return 0;
		}
		Damage *= FriendlyFireScale;
	}

	// Start code from DeathMatch.uc - Had to override this here because it was reducing
	// bite damage (which is 1) down to zero when the skill settings were low

	if ( (instigatedBy != None) && (InstigatedBy != Injured) && (Level.TimeSeconds - injured.SpawnTime < SpawnProtectionTime)
		&& (class<WeaponDamageType>(DamageType) != None || class<VehicleDamageType>(DamageType) != None) )
		return 0;

    Damage = super(UnrealMPGameInfo).ReduceDamage( Damage, injured, InstigatedBy, HitLocation, Momentum, DamageType );

    if ( instigatedBy == None)
        return Damage;

    DamageBeforeSkillAdjust = Damage;

    if ( Level.Game.GameDifficulty <= 3 )
    {
        if ( injured.IsPlayerPawn() && (injured == instigatedby) && (Level.NetMode == NM_Standalone) )
            Damage *= 0.5;
    }
    return (Damage * instigatedBy.DamageScaling);
	// End code from DeathMatch.uc
}

defaultproperties
{
	NormalWaves(0)=(WaveMask=67108864,WaveMaxMonsters=100,WaveDuration=30)
    NormalWaves(1)=(WaveMask=56193020,WaveMaxMonsters=30,WaveDuration=30,WaveDifficulty=0.100000)
    NormalWaves(2)=(WaveMask=56193020,WaveMaxMonsters=30,WaveDuration=30,WaveDifficulty=0.100000)
	NormalWaves(3)=(WaveMask=56193020,WaveMaxMonsters=30,WaveDuration=30,WaveDifficulty=0.100000)
	NormalWaves(4)=(WaveMask=56193020,WaveMaxMonsters=30,WaveDuration=30,WaveDifficulty=0.100000)
	NormalWaves(5)=(WaveMask=56193020,WaveMaxMonsters=30,WaveDuration=30,WaveDifficulty=0.100000)
	NormalWaves(6)=(WaveMask=56193020,WaveMaxMonsters=30,WaveDuration=30,WaveDifficulty=0.100000)
	NormalWaves(7)=(WaveMask=56193020,WaveMaxMonsters=30,WaveDuration=30,WaveDifficulty=0.100000)
	NormalWaves(8)=(WaveMask=56193020,WaveMaxMonsters=10,WaveDuration=30,WaveDifficulty=0.100000)
	NormalWaves(9)=(WaveMask=56193020,WaveMaxMonsters=10,WaveDuration=30,WaveDifficulty=0.100000)
	NormalWaves(10)=(WaveMask=56193020,WaveMaxMonsters=10,WaveDuration=30,WaveDifficulty=0.100000)
	NormalWaves(11)=(WaveMask=56193020,WaveMaxMonsters=10,WaveDuration=30,WaveDifficulty=0.100000)
	NormalWaves(12)=(WaveMask=56193020,WaveMaxMonsters=10,WaveDuration=30,WaveDifficulty=0.100000)
	NormalWaves(13)=(WaveMask=56193020,WaveMaxMonsters=10,WaveDuration=30,WaveDifficulty=0.100000)
	NormalWaves(14)=(WaveMask=56193020,WaveMaxMonsters=10,WaveDuration=30,WaveDifficulty=0.100000)
	NormalSpecialSquads(1)=(ZedClass=("ServerPerksV4C.DKFleshpound","ServerPerksV4C.DKShiver"),NumZeds=(1,8))
    NormalSpecialSquads(2)=(ZedClass=("ServerPerksV4C.DKFleshpound","ServerPerksV4C.DKShiver"),NumZeds=(1,8))
    NormalSpecialSquads(3)=(ZedClass=("ServerPerksV4C.DKFleshpound","ServerPerksV4C.DKShiver"),NumZeds=(1,8))
	NormalSpecialSquads(4)=(ZedClass=("ServerPerksV4C.DKFleshpound","ServerPerksV4C.DKShiver"),NumZeds=(1,8))
	NormalSpecialSquads(5)=(ZedClass=("ServerPerksV4C.DKFleshpound","ServerPerksV4C.DKShiver"),NumZeds=(1,8))
	NormalSpecialSquads(6)=(ZedClass=("ServerPerksV4C.DKFleshpound","ServerPerksV4C.DKShiver"),NumZeds=(1,8))
	NormalSpecialSquads(7)=(ZedClass=("ServerPerksV4C.DKFleshpound","ServerPerksV4C.DKShiver"),NumZeds=(1,8))
	NormalSpecialSquads(8)=(ZedClass=("ServerPerksV4C.DKFleshpound","ServerPerksV4C.DKShiver"),NumZeds=(1,8))
	NormalSpecialSquads(9)=(ZedClass=("ServerPerksV4C.DKFleshpound","ServerPerksV4C.DKShiver"),NumZeds=(1,8))
	NormalSpecialSquads(10)=(ZedClass=("ServerPerksV4C.DKFleshpound","ServerPerksV4C.DKShiver"),NumZeds=(1,8))
	NormalSpecialSquads(11)=(ZedClass=("ServerPerksV4C.DKFleshpound","ServerPerksV4C.DKShiver"),NumZeds=(1,8))
	NormalSpecialSquads(12)=(ZedClass=("ServerPerksV4C.DKFleshpound","ServerPerksV4C.DKShiver"),NumZeds=(1,8))
	NormalSpecialSquads(13)=(ZedClass=("ServerPerksV4C.DKFleshpound","ServerPerksV4C.DKShiver"),NumZeds=(1,8))
	NormalSpecialSquads(14)=(ZedClass=("ServerPerksV4C.DKFleshpound","ServerPerksV4C.DKShiver"),NumZeds=(1,8))
	FinalSquads(0)=(ZedClass=("ServerPerksV4C.DKGorefast","ServerPerksV4C.DKBloat"),NumZeds=(4,1))
    FinalSquads(1)=(ZedClass=("ServerPerksV4C.DKHusk","ServerPerksV4C.DKSiren","ServerPerksV4C.DKScrake"),NumZeds=(1,2,1))
    FinalSquads(2)=(ZedClass=("ServerPerksV4C.DKGorefast","ServerPerksV4C.DKSiren","ServerPerksV4C.DKHusk","ServerPerksV4C.DKFleshpound"),NumZeds=(5,1,1,1))
	EndGameBossClass="ServerPerksV4C.DKPatriarch"
	StandardMonsterClasses(0)=(MClassName="ServerPerksV4C.DKClot",Mid="A")
    StandardMonsterClasses(1)=(MClassName="ServerPerksV4C.DKCrawler",Mid="B")
    StandardMonsterClasses(2)=(MClassName="ServerPerksV4C.DKGorefast",Mid="C")
    StandardMonsterClasses(3)=(MClassName="ServerPerksV4C.DKStalker",Mid="D")
    StandardMonsterClasses(4)=(MClassName="ServerPerksV4C.DKScrake",Mid="E")
    StandardMonsterClasses(5)=(MClassName="ServerPerksV4C.DKFleshpound",Mid="F")
    StandardMonsterClasses(6)=(MClassName="ServerPerksV4C.DKBloat",Mid="G")
    StandardMonsterClasses(7)=(MClassName="ServerPerksV4C.DKSiren",Mid="H")
    StandardMonsterClasses(8)=(MClassName="ServerPerksV4C.DKHusk",Mid="I")
    StandardMonsterSquads(0)="2G"
	StandardMonsterSquads(1)="1G"
	StandardMonsterSquads(2)="4B"
	StandardMonsterSquads(3)="6A2G"
	StandardMonsterSquads(4)="8D"
	StandardMonsterSquads(5)="5A2C"
	StandardMonsterSquads(6)="3A3C"
	StandardMonsterSquads(7)="3A5B2C"
	StandardMonsterSquads(8)="1A4C"
	StandardMonsterSquads(9)="3A1C1H"
	StandardMonsterSquads(10)="3A1B2D2G1H"
	StandardMonsterSquads(11)="3A1E1G"
	StandardMonsterSquads(12)="2C2E"
	StandardMonsterSquads(13)="2A3C1E"
	StandardMonsterSquads(14)="2B4D1G2H"
	StandardMonsterSquads(15)="4A1C1I"
	StandardMonsterSquads(16)="9A"
	StandardMonsterSquads(17)="4D"
	StandardMonsterSquads(18)="4C"
	StandardMonsterSquads(19)="6B1I"
	StandardMonsterSquads(20)="2B2C3D1H"
	StandardMonsterSquads(21)="2A2B2C2H"
	StandardMonsterSquads(22)="2C1G"
	StandardMonsterSquads(23)="1I"
	StandardMonsterSquads(24)="3A2C1I"
	StandardMonsterSquads(25)="2I"
	StandardMonsterSquads(26)="9A"
	StandardMonsterSquads(27)="5C2E1G1H1I"
	StandardMonsterSquads(28)="9A"
	WaveStartSpawnPeriod=1.0
	StandardMaxZombiesOnce=40
	MaxZombiesOnce=40
	FallbackMonsterClass="ServerPerksV4C.DKStalker"
}
